#include "gamemenu.h"
#include <QKeyEvent>
#include <QFont>
#include <QBrush>
#include <QImage>

GameMenu::GameMenu(QObject *parent)
    : QGraphicsScene(parent)
{
    setSceneRect(0, 0, 800, 400);
    setupMenu();
}

void GameMenu::setupMenu()
{
    // 背景
    setBackgroundBrush(QBrush(QImage(":/image/D:/menu_bg.jpg").scaled(800, 400)));

    // 标题
    title = new QGraphicsPixmapItem(QPixmap(":/image/D:/title.jpg").scaled(400, 100));
    title->setPos(200, 50);
    addItem(title);

    // 开始游戏文本
    startText = new QGraphicsTextItem("开始游戏 (按S键)");
    QFont startFont("Arial", 24, QFont::Bold);
    startText->setFont(startFont);
    startText->setDefaultTextColor(Qt::white);
    int xPos = width()/2 - startText->boundingRect().width()/2;
    startText->setPos(xPos, 200);
    addItem(startText);

    // 退出游戏文本
    exitText = new QGraphicsTextItem("退出游戏 (按Q键)");
    QFont exitFont("Arial", 24, QFont::Bold);
    exitText->setFont(exitFont);
    exitText->setDefaultTextColor(Qt::white);
    xPos = width()/2 - exitText->boundingRect().width()/2;
    exitText->setPos(xPos, 250);
    addItem(exitText);
}

void GameMenu::keyPressEvent(QKeyEvent *event)
{
    switch(event->key()) {
    case Qt::Key_S:
        emit startGame();
        break;
    case Qt::Key_Q:
        emit exitGame();
        break;
    }
}
